home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 42
/
Amiga Format AFCD42 (Issue 126, Aug 1999).iso
/
-serious-
/
comms
/
other
/
micq-0.4.0
/
ui.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-05-14
|
33KB
|
1,062 lines
/*********************************************
**********************************************
This file has the "ui" functions that read input
and send messages etc.
This software is provided AS IS to be used in
whatever way you see fit and is placed in the
public domain.
Author : Matthew Smith April 23, 1998
Contributors : Nicolas Sahlqvist April 27, 1998
Michael Ivey May 4, 1998
Ulf Hedlund -- Windows Support
Michael Holzt May 5, 1998
Changes :
22-6-98 Added the save and alter command and the
new implementation of auto
**********************************************
**********************************************/
#include "micq.h"
#include "datatype.h"
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <unistd.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "mreadline.h"
#endif
#include <fcntl.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <assert.h>
#include "ui.h"
#ifdef __SASC
#include "amiga-dt.h"
#endif
USER_INFO_STRUCT user;
#ifdef UNIX
char *strdup( const char * );
int strcasecmp( const char *, const char * );
#endif
BOOL Do_Multiline( SOK_T sok, char *buf )
{
static int offset=0;
static char msg[1024];
msg[ offset ] = 0;
if ( strcmp( buf, END_MSG_STR ) == 0 )
{
icq_sendmsg( sok, multi_uin, msg, NORM_MESS );
M_print( MESSAGE_SENT_1_STR );
Print_UIN_Name( multi_uin );
M_print( MESSAGE_SENT_2_STR );
last_uin = multi_uin;
offset = 0;
return FALSE;
}
else if ( strcmp( buf, CANCEL_MSG_STR ) == 0 )
{
M_print( MESSAGE_CANCELED_STR );
last_uin = multi_uin;
offset = 0;
return FALSE;
}
else
{
if ( offset + strlen( buf ) < 450 )
{
strcat( msg, buf );
strcat( msg, "\r\n" );
offset += strlen( buf ) + 2;
return TRUE;
}
else
{
M_print( MESSAGE_BUFFER_FULL_STR );
M_print( MESSAGE_SENT_1_STR );
Print_UIN_Name( multi_uin );
M_print( MESSAGE_SENT_2_STR );
icq_sendmsg( sok, multi_uin, msg, NORM_MESS );
last_uin = multi_uin;
offset = 0;
return FALSE;
}
}
}
void Info_Update( SOK_T sok, char *buf )
{
switch ( status ) {
case NEW_NICK:
user.nick = strdup( (char *) buf );
M_print ( FIRST_NAME_UPDATE_STR );
status++;
break;
case NEW_FIRST:
user.first = strdup( (char *) buf );
M_print ( LAST_NAME_UPDATE_STR );
status++;
break;
case NEW_LAST:
user.last = strdup( (char *) buf );
M_print ( EMAIL_UPDATE_STR );
status++;
break;
case NEW_EMAIL:
user.email = strdup( (char *) buf );
M_print( AUTH_QUESTION_STR );
status++;
break;
case NEW_AUTH:
if ( ! strcasecmp( buf, NO_STR ) )
{
user.auth = FALSE;
Update_User_Info( sok, &user );
/* free( user.nick );
free( user.last );
free( user.first );
free( user.email ); */
status = 0;
}
else if ( ! strcasecmp( buf, YES_STR ) )
{
user.auth = TRUE;
Update_User_Info( sok, &user );
free( user.nick );
free( user.last );
free( user.first );
free( user.email );
status = 0;
}
else
{
M_print( YESNO_RESPONSE_STR );
M_print( AUTH_QUESTION_STR );
}
break;
}
}
void User_Search( SOK_T sok, char *buf )
{
switch (status) {
case SRCH_START:
M_print ( "Enter the Users E-mail address : ");
status++;
break;
case SRCH_EMAIL:
user.email = strdup( (char *) buf );
M_print( "Enter the Users Nick : ");
status++;
break;
case SRCH_NICK:
user.nick = strdup( (char *) buf );
M_print ( "Enter The Users First Name : ");
status++;
break;
case SRCH_FIRST:
user.first = strdup( (char *) buf );
M_print ( "Enter The Users Last Name : ");
status++;
break;
case SRCH_LAST:
user.last = strdup( (char *) buf );
start_search( sok, user.email, user.nick,
user.first, user.last );
status = 0;
break;
}
}
BOOL Do_Multiline_All( SOK_T sok, char *buf )
{
static int offset=0;
static char msg[1024];
char * temp;
int i;
msg[ offset ] = 0;
if ( strcmp( buf, END_MSG_STR ) == 0 )
{
for ( i=0; i < Num_Contacts; i++ ) {
temp = strdup ( msg );
icq_sendmsg( sok, Contacts[i].uin, temp, MRNORM_MESS );
free( temp );
}
M_print( "Message sent!" );
offset = 0;
return FALSE;
}
else if ( strcmp( buf, CANCEL_MSG_STR ) == 0 )
{
M_print( MESSAGE_CANCELED_STR );
offset = 0;
return FALSE;
}
else
{
if ( offset + strlen( buf ) < 450 )
{
strcat( msg, buf );
strcat( msg, "\r\n" );
offset += strlen( buf ) + 2;
return TRUE;
}
else
{
M_print( MESSAGE_BUFFER_FULL_STR );
for ( i=0; i < Num_Contacts; i++ ) {
temp = strdup( msg );
icq_sendmsg( sok, Contacts[i].uin, temp, MRNORM_MESS );
free( temp );
}
offset = 0;
return FALSE;
}
}
}
/******************************************************
Read a line of input and processes it.
*******************************************************/
void Get_Input( SOK_T sok )
{
char buf[1024]; /* This is hopefully enough */
char *cmd;
char *arg1;
char *arg2;
int i;
memset( buf, 0, 1024 );
R_getline( buf, 1024 );
buf[1023]=0; /* be safe */
if ( status == 1 )
{
if ( ! Do_Multiline( sok, buf ) )
{
status = 2;
} else {
R_doprompt ( MSG_PROMPT_STR );
}
}
else if ( status == 3 )
{
if ( ! Do_Multiline_All( sok, buf ) ) {
status = 2;
} else {
R_doprompt ( MSGA_PROMPT_STR );
}
}
else if ( ( status >= NEW_NICK) && ( status <= NEW_AUTH) )
{ Info_Update( sok, buf ); }
else if ( ( status >= SRCH_START) && ( status <= SRCH_LAST) )
{ User_Search( sok, buf ); }
else
{
if ( buf[0] != 0 )
{
if ( '!' == buf[0] )
{
R_pause ();
system( &buf[1] );
R_resume ();
Prompt();
return;
}
cmd = strtok( buf, " \n\t" );
if ( NULL == cmd )
{
Prompt();
return;
}
/* goto's removed and code fixed by Paul Laufer. Enjoy! */
if ( ( strcasecmp( cmd , "quit" ) == 0 ) ||
( strcasecmp( cmd , "/quit" ) == 0 ) )
{ Quit = TRUE; }
else if ( strcasecmp( cmd, quit_cmd ) == 0 )
{ Quit = TRUE; }
else if ( strcasecmp( cmd, sound_cmd ) == 0 )
{
if ( SOUND_ON == Sound )
{
Sound = SOUND_OFF;
M_print( "Sound" SERVCOL " OFF" NOCOL ".\n" );
}
else if ( SOUND_OFF == Sound )
{
Sound = SOUND_ON;
M_print( "Sound" SERVCOL " ON" NOCOL ".\n" );
}
}
else if ( strcasecmp( cmd, change_cmd ) == 0 )
{ Change_Function( sok ); }
else if ( strcasecmp( cmd, rand_cmd ) == 0 )
{ Random_Function( sok ); }
else if ( strcasecmp( cmd, "set" ) == 0 )
{ Random_Set_Function( sok ); }
else if ( ! strcasecmp( cmd, color_cmd ) )
{
Color = !Color;
if ( Color )
{
#ifdef FUNNY_MSGS
M_print( SERVCOL "Being " MESSCOL "all " CLIENTCOL
"colorful " NOCOL
"and " SERVCOL "cute " CONTACTCOL "now\n" NOCOL );
#else
M_print( "Color is " MESSCOL "on" NOCOL ".\n" );
#endif
}
else
{
#ifdef FUNNY_MSGS
M_print( SERVCOL "Dull colorless mode on, resistance is futile\n" NOCOL );
#else
M_print( "Color is " MESSCOL "off" NOCOL ".\n" );